How style sheets are embedded in HTML Unlike HTML, the CSS1 mechanism keeps formatting instructions for HTML tags together in a container enclosed in a <STYLE> tag (= the style sheet), instead of interspersing them with the flow of HTML code. When loading the page, the browser reads the formatting instructions contained in that tag and caches them with the page. Subsequently, whenever the program finds an instance of an HTML tag for which custom format definitions exist in the style sheet, it applies those rules. Cascading style sheets are embedded in the HTML using the <STYLE> tag. This tag has a TYPE attribute; its value is set to "text/css" by default. TYPE="text/css" tells the browser to interpret any formatting instructions enclosed in the <STYLE> tag as a CSS1 style sheet and build the screen display according to the rules specified within. Although CSS1 is the predominant style sheet mechanism currently in use on the Web, this type description may reduce conflicts with future style sheet mechanisms on the Web. The following is an example of a basic, yet complete style sheet: <STYLE type="text/css"> <!-- h1 {font-size: 36pt} --> </STYLE> You'll notice that the rules are enclosed in <!-- and --> HTML comment tags. These tags instruct browsers that are unaware of the style tag to ignore the tags (unknown tags are ignored). CSS1 containment in HTML pages is based on external or internal style sheets. Adobe GoLive supports the four basic methods of embedding--the <LINK> tag and the @import command for external style sheets, and the <STYLE> tag and class element for internal style sheets. External style sheets External style sheets are text-only documents containing nothing but style definitions. They can either be referenced or imported: <HTML> <HEAD> <TITLE>title</TITLE> <LINK REL=STYLESHEET TYPE="text/css" HREF="http://style.com/cool" TITLE="Cool"> </HEAD> <BODY> <H1>This page has an external stylesheet attached.</H1> </BODY> </HTML> A referenced external style sheet works much like a master style sheet in a word-processing application. As with style sheets for word processing files, some definitions are "hard wired" to certain types of text. Also, you can override the definitions within the document and assign styles explicitly to selected text. <HTML> <HEAD> <TITLE>title</TITLE> <STYLE TYPE="text/css"> @import url(http://style.com/basic); </STYLE> </HEAD> <BODY> <H1>This page has an imported stylesheet.</H1> </BODY> </HTML> Internal style sheets Internal style sheets are confined to the document they are contained in. There are several methods for embedding internal style sheets: <HTML> <HEAD> <TITLE>title</TITLE> <STYLE TYPE="text/css"> <!-- H1 { font-weight: bold; font-size: 24pt; font-family: sans-serif; } --> </STYLE> </HEAD> <BODY> <H1>This page holds an internal stylesheet.</H1> </BODY> </HTML> An internal <STYLE> element with tag selectors works much like a word processor style sheet embedded in a file, the only difference being that its styles are "hard-wired" to certain text elements. You can change definitions within the document, but you cannot assign a style explicitly to selected text. The CLASS element closely resembles user-defined paragraph and character styles in a word-processing application in that the author creates and applies the style definition. CLASS style elements are easily recognized by their name, which begins with a period, as in .headline. An example follows: <HTML> <HEAD> <TITLE>title</TITLE> <STYLE TYPE="text/css"> <!-- .headline { color: #00FF00 } .bodycolored { color: #0099FF } --> </STYLE> </HEAD> <BODY> <H1 CLASS=headline>This headline is formatted using a CLASS element.</H1> <P CLASS=bodycolored>This paragraph has a custom color.</P> </BODY> </HTML> The CLASS element works much like a paragraph or character style in a word-processing application. You can change its definition within the document and assign it to selected paragraphs. The ID element is a special style element. It also consists of a style definition in the header but is locally confined to a unique element within the page. An alphanumeric identifier that appears within the definition and the tag it controls makes the assignment. The name of ID style elements starts with a pound sign, as in #yz98. An example follows: <HTML> <HEAD> <TITLE>title</TITLE> <STYLE TYPE="text/css"> <!-- #z99y { letter-spacing: 2em } --> </STYLE> </HEAD> <BODY> <P ID=z98y>This text has extra-wide letter spacing.</P> </BODY> </HTML> Using Cascading Style Sheets > About cascading style sheets > How style sheets are embedded in HTML |